#!/usr/bin/env node
"""测试前端到后端的连接"""

const axios = require('axios');

async function testConnection() {
    console.log('🔍 测试前端到后端连接...');
    
    try {
        // 测试健康检查
        console.log('\n1. 测试健康检查:');
        const healthResponse = await axios.get('http://localhost:8000/api/health');
        console.log('✅ 健康检查成功:', healthResponse.data);
        
        // 测试激活码验证
        console.log('\n2. 测试激活码验证:');
        const verifyResponse = await axios.post('http://localhost:8000/api/auth/verify-code', {
            code: 'genglongtao'
        });
        console.log('✅ 激活码验证成功:', verifyResponse.data);
        
        // 测试用户激活
        console.log('\n3. 测试用户激活:');
        const activateResponse = await axios.post('http://localhost:8000/api/auth/activate', {
            code: 'genglongtao'
        });
        console.log('✅ 用户激活成功:', activateResponse.data);
        
    } catch (error) {
        console.log('❌ 测试失败:');
        if (error.response) {
            console.log('   状态码:', error.response.status);
            console.log('   错误信息:', error.response.data);
        } else {
            console.log('   网络错误:', error.message);
        }
    }
}

testConnection();
